Add tests for other cargo cmds + -L propagation
authorAlex Crichton <alex@alexcrichton.com>
Sat, 1 Nov 2014 00:36:48 +0000 (17:36 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 5 Nov 2014 19:37:34 +0000 (11:37 -0800)
src/cargo/ops/cargo_run.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile_custom_build.rs

index b464c684f227fe6ef81886dfc6934aebc9d8b07c..39b3e369a89ab1bb02438f49e1ea98c64a171e6b 100644 (file)
@@ -22,7 +22,8 @@ pub fn run(manifest_path: &Path,
             LibTarget(_) => false,
         };
         let matches_name = name.as_ref().map_or(true, |n| n.as_slice() == a.get_name());
-        matches_kind && matches_name && a.get_profile().get_env() == env
+        matches_kind && matches_name && a.get_profile().get_env() == env &&
+            !a.get_profile().is_custom_build()
     });
     let bin = try!(bins.next().require(|| {
         human("a bin target must be available for `cargo run`")
index f1b29c0bda534b11d7a192d5bb657bc3220571be..f6aae0cad46caf19af0f5afb15ca148e98992402 100644 (file)
@@ -236,7 +236,9 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
             _ => format!("custom build commands"),
         };
         let dirty = proc(desc_tx: Sender<String>) {
-            desc_tx.send_opt(desc).ok();
+            if desc.len() > 0 {
+                desc_tx.send_opt(desc).ok();
+            }
             for cmd in build_cmds.into_iter() { try!(cmd(desc_tx.clone())) }
             dirty(desc_tx)
         };
index 4fbc82dcdaee7cf5beec3255e603d500f4315711..d94861df262e8ba9b86ef917faa4f86364db7859 100644 (file)
@@ -1,7 +1,7 @@
 use std::io::File;
 
 use support::{project, execs, cargo_dir};
-use support::{COMPILING, RUNNING, FRESH};
+use support::{COMPILING, RUNNING, DOCTEST};
 use support::paths::PathExt;
 use hamcrest::{assert_that};
 
@@ -423,12 +423,120 @@ test!(rebuild_continues_to_pass_env_vars {
     File::create(&p.root().join("some-new-file")).unwrap();
 
     assert_that(p.process(cargo_dir().join("cargo")).arg("build").arg("-v"),
+                execs().with_status(0));
+})
+
+test!(testing_and_such {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("src/lib.rs", "")
+        .file("build.rs", r#"
+            fn main() {}
+        "#);
+
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0));
+    p.root().move_into_the_past().unwrap();
+
+    File::create(&p.root().join("file1")).unwrap();
+
+    assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{fresh} a v0.5.0 (file://[..])
 {compiling} foo v0.5.0 (file://[..])
-{running} `[..]build-script-build`
-{running} `rustc [..] --crate-name foo [..]`
-", compiling = COMPILING, running = RUNNING, fresh = FRESH).as_slice()));
+{running} `rustc [..] --test [..]`
+{running} `[..]foo-[..]`
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} foo
+{running} `rustdoc --test [..]`
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING, doctest = DOCTEST).as_slice()));
+
+    assert_that(p.process(cargo_dir().join("cargo")).arg("doc").arg("-v"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.5.0 (file://[..])
+{running} `rustdoc [..]`
+{running} `rustc [..]`
+", compiling = COMPILING, running = RUNNING).as_slice()));
+
+    File::create(&p.root().join("src/main.rs")).write_str("fn main() {}").unwrap();
+    assert_that(p.process(cargo_dir().join("cargo")).arg("run"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.5.0 (file://[..])
+{running} `target[..]foo`
+", compiling = COMPILING, running = RUNNING).as_slice()));
 })
 
+test!(propagation_of_l_flags {
+    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+            [dependencies.a]
+            path = "a"
+        "#)
+        .file("src/lib.rs", "")
+        .file("a/Cargo.toml", r#"
+            [project]
+            name = "a"
+            version = "0.5.0"
+            authors = []
+            links = "bar"
+            build = "build.rs"
+
+            [dependencies.b]
+            path = "../b"
+        "#)
+        .file("a/src/lib.rs", "")
+        .file("a/build.rs", r#"
+            fn main() {
+                println!("cargo:rustc-flags=-L bar");
+            }
+        "#)
+        .file("b/Cargo.toml", r#"
+            [project]
+            name = "b"
+            version = "0.5.0"
+            authors = []
+            links = "foo"
+            build = "build.rs"
+        "#)
+        .file("b/src/lib.rs", "")
+        .file("b/build.rs", "bad file")
+        .file(".cargo/config", format!(r#"
+            [target.{}.foo]
+            rustc-flags = "-L foo"
+        "#, target).as_slice());
+
+    assert_that(p.cargo_process("build").arg("-v").arg("-j1"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} a v0.5.0 (file://[..])
+{running} `rustc build.rs [..]`
+{compiling} b v0.5.0 (file://[..])
+{running} `rustc [..] --crate-name b [..]-L foo[..]`
+{running} `[..]a-[..]build-script-build`
+{running} `rustc [..] --crate-name a [..]-L bar[..]-L foo[..]`
+{compiling} foo v0.5.0 (file://[..])
+{running} `rustc [..] --crate-name foo [..] -L bar[..]-L foo[..]`
+", compiling = COMPILING, running = RUNNING).as_slice()));
+})